//index.js文件中引入
import Vue from "vue";
import VueRouter from "vue-router";

import Login from '@/views/login';
// 默认导入目录下的 index.vue 文件，等价于 ./views/register/index.vue
import Register from "@/views/register";
import Layout from '@/components/Layout.vue'
import Home from '@/views/home';
import Teacher from '@/views/teacher';
import Student from '@/views/student';
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {undefined
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter);
const routes = [
  {
    path: '/register',
    name: 'register',
    component: Register
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    // 基础布局
    path: '/',
    name: 'layout',
    component: Layout,
    redirect:'/home',
    children:[
      {
        path:'/home',
        component:Home,
        meta:{title:'首页'}
      }
    ]
},
{
  path:'/teacher',
  component:Layout,
  children:[
    {
      path:'/',
      component:Teacher,
      meta:{title:'教师管理'}
    }
  ]
},
{
  path:'/student',
  component:Layout,
  children:[
    {
      path:'/',
      component:Student,
      meta:{title:'学员管理'}
    }
  ]
},
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
})
export default router
